<%@ page contentType="text/html;charset=utf-8" language="java"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%> 
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%> 
<script language="javascript" src="../js/ciphering.js"></script>
<script language="javascript" src="../js/checkEmail.js"></script>
<script language="javascript" src="../js/checkNumChar.js"></script>
<html:html>
<head>
		<META http-equiv=Content-Type content="text/html; charset=utf-8">
		<LINK href="../styles/sciencee.css"  type=text/css rel=stylesheet>
		<style type="text/css"></style>
		<title>CGProject</title>
		<html:base/>
</head>
<body>

	<html:form action="/addUser" onsubmit="return  submitAddUser()">
	<table width="100%" cellspacing="1" id="table2" style="border: 1px solid #C0C0C0">
		<tr>
			<td height="25" align="left" bgcolor="#EEF2F7" style="padding:0; " colspan="2" width="100%">&nbsp;<b> <bean:message key="reguser.add"/></b></td>
		</tr>
		<tr>
			<td height="25" align="left" width="15%" style="border-right:1px dotted #C0C0C0; border-bottom:1px dotted #C0C0C0; padding:0; ">&nbsp;<bean:message key="reguser.name"/> &nbsp;*</td>
			<td height="25" align="left" style="border-bottom:1px dotted #C0C0C0; padding:0; ">&nbsp;<html:text property="regname" size="20" style="border:1px solid #C0C0C0; font-family: Tahoma; font-size: 11px" />&nbsp;
			<input type="button" value="Check Availability" name="test" onclick="testRegNme('./testUserName.do?RegName='+addUserForm.regname.value)" style="font-family: Tahoma; font-size: 11px"></td>
		</tr>
		<tr>
			<td height="25" align="left" width="15%" style="border-right:1px dotted #C0C0C0; border-bottom:1px dotted #C0C0C0; padding:0; ">
			&nbsp; <bean:message key="reguser.password"/>&nbsp; *</td>
			<td height="25" align="left" style="border-bottom:1px dotted #C0C0C0; padding:0; ">
			&nbsp;<html:password property="password" size="20" maxlength="20"style="border:1px solid #C0C0C0; font-family: Tahoma; font-size: 11px" />			
			<html:hidden property="cipherCode"/>
			<bean:message key="reguser.pwdtip"/></td>
		</tr>
		<tr>
			<td height="25" align="left" width="15%" style="border-right:1px dotted #C0C0C0; border-bottom:1px dotted #C0C0C0; padding:0; ">&nbsp;<bean:message key="reguser.retype"/>&nbsp;*</td>
			<td height="25" align="left" style="border-bottom:1px dotted #C0C0C0; padding:0; ">&nbsp;<html:password property="repassword" size="20" maxlength="20" style="border:1px solid #C0C0C0; font-family: Tahoma; font-size: 11px" /></td>
		</tr>
		<tr>
			<td height="25" align="left" width="15%" style="border-right:1px dotted #C0C0C0; border-bottom:1px dotted #C0C0C0; padding:0; ">
			&nbsp; <bean:message key="reguser.empid"/>*</td>
			<td height="25" align="left" style="border-bottom:1px dotted #C0C0C0; padding:0; ">
			&nbsp;<html:text property="empNo" size="20" style="border:1px solid #C0C0C0; font-family: Tahoma; font-size: 11px" />
			<input type="button" value="Select Empoloyee" name="B1" style="font-family: Tahoma; font-size: 11px" onclick="openwin('<%=request.getContextPath() %>/regUser/intoQuery.do?Flag=2')"></td> 
		</tr>
		<tr>
			<td height="25" align="left" width="15%" style="border-right:1px dotted #C0C0C0; border-bottom:1px dotted #C0C0C0; padding:0; ">
			&nbsp; <bean:message key="reguser.role"/></td>
			<td height="25" align="left" style="border-bottom:1px dotted #C0C0C0; padding:0; ">
			&nbsp;<html:select property="roleSelect" size="8" style="font-family: Tahoma; font-size: 11px" multiple="true">
					<html:options  collection="Roles"
								   property="roleId"
								   labelProperty="roleName"/>
				</html:select><font color=#990000>(<bean:message key="reguser.selecttip"/>,<bean:message key="reguser.viewtip"/>)</font></td>
		</tr>
		<tr>
			<td height="25" align="left" width="20%" style="border-right:1px dotted #C0C0C0; border-bottom:1px dotted #C0C0C0; padding:0; ">
			&nbsp; <bean:message key="reguser.defaultrole"/></td>
			<td height="25" align="left" style="border-bottom:1px dotted #C0C0C0; padding:0; ">
			&nbsp;<html:select size="1" property="primaryRole" style="font-family: Tahoma; font-size: 11px">
			<html:options  collection="Roles2"
								   property="roleId"
								   labelProperty="roleName"/>
				</html:select></td>
		</tr>
		<tr>
		<td height="25" align="left" style="border-right:1px dotted #C0C0C0; border-bottom:1px dotted #C0C0C0; padding:0; " colspan="2">
			&nbsp;<html:submit style="font-family: Tahoma; font-size: 11px"><bean:message key="submit"/></html:submit>
			<html:reset style="font-family: Tahoma; font-size: 11px"><bean:message key="reset"/></html:reset>
			&nbsp;&nbsp;<html:link page="/index.do"><font face="Verdana" style="font-size: 9pt">[<bean:message key="back"/>]</font></html:link>
			</td>
		</tr>
	</table>
	</html:form>
</body>
</html:html>
<script language="javascript">
function checkStrLen(chString)
{
	if(chString.length<6)
	{
		window.alert("Password is unavailable");
		return 0;
	}
	if(chString.length>20)
	{
		window.alert("Password is unavailable");
		return 0;
	}
	else return 1;
}
function openwin(url)
{
 	window.open(url,'newwindow','width=400,height=200');
}
function testRegNme(url)
{
		if(addUserForm.regname.value=="")
		{
			alert("No RegName");
			window.document.addUserForm.regname.focus();
			return false;
		}
		else
		{
			window.open(url,'newwindow','width=400,height=200');
		}

}

function submitAddUser()
{
	if(addUserForm.regname.value=="")
	{
		window.alert("No RegName");
 		document.addUserForm.regname.focus();
 		return false;
  	}  
  	//处理口令的输入	  	
  	if(addUserForm.password.value=="")
  	{
  		window.alert("Please input password");
  		document.addUserForm.password.focus();
  		return false;
  	}	  	
  	if(0==checkStrLen(addUserForm.password.value))
  	{
  		document.addUserForm.password.focus();
  		return false;
  	}
  	if(false==checkNumChar(addUserForm.password.value))
  	{
  	
  		window.alert("Password is unavailable.");
  		document.addUserForm.password.focus();
  		return false;  	
  	}
  		
  	if(addUserForm.repassword.value=="")
  	{
  		window.alert("Password is unavailable.");
  		document.addUserForm.repassword.focus();
  		return false;  
  	}
  	if(addUserForm.repassword.value!=addUserForm.password.value)
  	{
  		window.alert("Password is unavailable.");
  		document.addUserForm.password.focus();
  		document.addUserForm.repassword.blur();
  		return false;  
  	}//End 处理口令的输入
    	
  	if(addUserForm.empNo.value=="")
  	{
  		window.alert("Please select a employee");
  		document.addUserForm.empNo.focus();
  		return false;
  	}

   	if(addUserForm.roleSelect.options[addUserForm.roleSelect.selectedIndex].value=='0')
  	{
  		window.alert("No role");
  		document.addUserForm.roleSelect.focus();
  		return false;  
  	}
  	
   	if(addUserForm.primaryRole.value=="0")
  	{
  		window.alert("No default role");
  		document.addUserForm.primaryRole.focus();
  		return false;
  	}
  	
   	addUserForm.cipherCode.value=MD5(window.document.addUserForm.password.value);
  	window.document.addUserForm.submit();
}

</script>				

			


